package view;

import domain.ATM;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;


import java.net.URL;
import java.util.ResourceBundle;

public class ReceiptViewController  implements ControlledStage, Initializable {
    private StageController myController;
    private ATM atm;


    @FXML
    private TextArea receipt;
    @FXML
    private Button takeReceipt;

    public void setStageController(StageController stageController) {
        this.myController = stageController;
        atm = myController.getAtm();
        receipt.setText(atm.isToPrintReceipt(true));
    }


    public void initialize(URL location, ResourceBundle resources) {

    }

    public void goToMain(){
        myController.setStage(MainApp.mainViewID);
    }



    @FXML
    public void takeReceiptAction(ActionEvent actionEvent) {
        boolean b = atm.getCurTransaction().getTransType().equalsIgnoreCase("CWD");
        String viewID = b?MainApp.withdrawalViewID:MainApp.depositViewID;
        atm.endTransaction();
        myController.getStage(MainApp.receiptViewID).close();
        myController.setStage(MainApp.mainViewID,viewID);
    }
}
